package com.gzdict.common.net

import com.gzdict.common.utils.LogUtil.logi
import com.gzdict.common.utils.SPKey
import com.gzdict.common.utils.getStringSP
import okhttp3.Interceptor
import okhttp3.Response


/**
 * 描述：请求头拦截
 * @author: create by shang
 * @Date: 2024/3/8 0008 15:12
 *
 */

class HeaderInterceptor : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val token = getStringSP(SPKey.KEY_TOKEN)
        "token == $token".logi()
        val newRequest = chain.request().newBuilder().apply {
            addHeader("Content-Type", "application/json")
            token?.let { header("Authorization", token) }
        }.build()
        return chain.proceed(newRequest)
    }
}